<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="分类名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入分类名称" clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <TableCard>
            <el-row :gutter="10" class="mb8">
                <el-alert title="权限说明" type="success" :closable="false" style="padding: 20px">
                    <span style="font-weight: 900">设置参考步骤：</span>
                    <span style="color: blue">第一步、</span>可以优先设置企业的【角色】与【文件夹】的权限。
                    <span style="color: blue">第二步、</span>针对某些特殊用户，使用【按用户授权】功能，为其设置特殊的个性化文件夹权限（可以省略）。
                    <span style="color: blue">第三步、</span>配置全局【档案分类】权限，设置通用的分类权限<span style="color: red">（例如某些类型的档案，不需要进行权限控制）</span>。
                    <span style="color: blue">第四步、</span>针对某一指定的档案文件，单独设置其特殊个性化权限（可以省略）<br/>
                    <span style="font-weight: 900">无需验证权限（档案）：1、这一类的档案将不会验证权限（所有人拥有所有的权限）。</span><br/>
                    <span style="font-weight: 900">查看权限（档案）：</span>1、在档案浏览中显示该档案。2、可以允许用户右键查看档案详细信息。<br/>
                    <span style="font-weight: 900">修改权限（档案）：</span>1、允许用户对修改【档案信息】（重命名等）。<span style="color: red">2、允许用户对【档案】进行【移动】。3、允许用户对【档案文件】进行【移动】。</span><br/>
                    <span style="font-weight: 900">删除权限（档案）：</span><span style="color: red">1、允许用户对【档案】进行删除。</span>
                </el-alert>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>

            <el-table :border="Global.tableShowBorder" v-loading="loading" :data="amGroupList">
                <el-table-column label="分类名称" align="center" prop="name"/>
                <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/>
                <el-table-column label="无需验证权限" align="center" prop="notNeed" width="180">
                    <template slot-scope="scope">
                        <el-switch v-model="scope.row.authNone" active-value="1" inactive-value="0" @change="changeOperateAuth(scope.row)"></el-switch>
                    </template>
                </el-table-column>
                <el-table-column label="查看" align="center" prop="view" width="180">
                    <template slot-scope="scope">
                        <el-switch v-model="scope.row.authView" active-value="1" inactive-value="0" @change="changeOperateAuth(scope.row)"></el-switch>
                    </template>
                </el-table-column>
                <el-table-column label="修改" align="center" prop="update" width="180">
                    <template slot-scope="scope">
                        <el-switch v-model="scope.row.authUpdate" active-value="1" inactive-value="0" @change="changeOperateAuth(scope.row)"></el-switch>
                    </template>
                </el-table-column>
                <el-table-column label="删除" align="center" prop="delete" width="180">
                    <template slot-scope="scope">
                        <el-switch v-model="scope.row.authDelete" active-value="1" inactive-value="0" @change="changeOperateAuth(scope.row)"></el-switch>
                    </template>
                </el-table-column>
            </el-table>

            <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
        </TableCard>
    </div>
</template>

<script>
import {listAmGroup,updateAmGroup} from "@/api/am/amGroup";
import {allotRoleFolder} from "@/api/am/authRole";
import {allotUserFolder} from "@/api/am/authUser";

export default {
    name: "AmGroup",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 档案分类表格数据
            amGroupList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                name: null,
                userId: null,
                deptId: null
            },
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 查询档案分类列表 */
        getList() {
            this.loading = true;
            listAmGroup(this.queryParams).then(response => {
                this.amGroupList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        changeOperateAuth(row){
            let data = {};
            data.id = row.id;
            data.authNone = row.authNone;
            data.authView = row.authView;
            data.authUpdate = row.authUpdate;
            data.authDelete = row.authDelete;
            data.folderFileId = row.folderId;
            console.log(data)
            updateAmGroup(data).then(res=>{
                if(200==res.code){
                    this.$modal.msgSuccess("授权成功");
                    this.getList();
                }
            })
        }
    }
};
</script>
